import { defineStore } from "pinia"
import { reactive } from 'vue';
import { IRoleBasic } from '@/api/interface'

// interface IRoleBasic {
//   name: string;
//   profession: string;
//   sex: string;
//   [key: string]: any;
// }

// 人物属性
// export const useBasicStore = defineStore('basic', () => {
//   const basic = reactive<IRoleBasic>({
//     name: '',
//     profession: '',
//     sex: ''
//   });

//   function setData(data: IRoleBasic) {
//     if (typeof data === 'object') {
//       Object.keys(data).forEach((key: string) => {
//         if (basic.hasOwnProperty(key)) {
//           basic[key] = data[key];
//         }
//       });
//     }
//   }
//   return { basic, setData };
// });

export interface IBasicState {
	basic: IRoleBasic
}

export const useBasicStore = defineStore({
  id:'basic',
  state:() => (
    {
      basic:{
        name: '',
        profession: '',
        sex: ''
      }
    }  as IBasicState
  ),
  actions: {
    setData(data: any) {
      if(typeof data === 'object'){
        Object.keys(data).forEach((key: string) => {
          if(this.$state.basic.hasOwnProperty(key)){
            this.$state.basic[key] = data[key]
          }
        })
      }
    }
  }
})